/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.socialNet.db;

import com.bionic.socialNet.dao.abstractClasses.DAOFactory;
import com.bionic.socialNet.entities.LoginData;
import com.bionic.socialNet.manager.ConnectionManager;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;

/**
 *
 * @author Ann
 */
public class DB {

    private DAOFactory daoFactory;
    private Connection connection;
    private static DB instance;

    public static DB getInstance() {
        if (instance == null) {
            instance = new DB();
        }
        return instance;
    }

    private DB() {
        try {
            connection = ConnectionManager.getInstance().getConnection();
        } catch (SQLException e) {
            //log error
        } catch (NamingException e) {
            //   log error
        }
    }

    public Connection getConnection() {
        return connection;
    }

    private void createDAOFActory() {
        daoFactory = DAOFactory.getDAOFactory(DAOFactory.ORACLE);
    }

    public DAOFactory getFactory() {
        if (daoFactory == null) {
            createDAOFActory();
        }
        return daoFactory;
    }

    
    private boolean AlterSession() {
        Statement stAlter = null;
        if (connection == null) {
            return false;
        }
        try {
            stAlter = connection.createStatement();
            stAlter.execute("alter session set current_schema = scn");
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        } finally {
            try {
                stAlter.close();
            } catch (Throwable ignored) {
            }
        }

    }
}
